import 'package:flutter/material.dart';
// 首页
import '../home/home.dart';
// 分类
import '../sort/sort.dart';
// 品味
import '../taste/taste.dart';
// 购物车
import '../shoppingcar/shoppingCar.dart';
// 我的
import '../my/my.dart';

class BottomNavigationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => BottomNavigationWidgetState();
}

class BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  // 导航栏文字
  var appBarTitle=['首页','分类','品味','购物车','我的'];
  // 导航栏小图标
  var appBarIcon=[Icons.home,Icons.apps,Icons.local_mall,Icons.local_grocery_store,Icons.account_box];
  int _currentIndex = 0;
  List<Widget> list = List();

// 导航栏文字选中颜色
  Text getTabTitle(int curIndex){
    if(curIndex==_currentIndex){
      return new Text(appBarTitle[curIndex],
      style: new TextStyle(fontSize: 14.0,color:const Color(0xff845F3F)));
    }else{
      return new Text(appBarTitle[curIndex],
      style: new TextStyle(fontSize: 14.0, color: const Color(0xff696969)));
    }
  }

// 小图标改变选中颜色
  Icon getIcon(int curIndex){
    if(curIndex==_currentIndex){
      return Icon(appBarIcon[curIndex],color:const Color(0xff845F3F));
    }else{
      return Icon(appBarIcon[curIndex],color:const Color(0xff696969));
    }
  }
// 初始化数据
  @override
  void initState() {
    list
      ..add(HomePage())
      ..add(SortPage())
      ..add(TastePage())
      ..add(ShoppingCarPage(
        items:new  List<String>.generate(1000, (i)=>"Item $i")
      ))
      ..add(MyPage());
    super.initState();
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: list[_currentIndex],
      bottomNavigationBar:new BottomNavigationBar(
        items:<BottomNavigationBarItem> [
          new BottomNavigationBarItem(icon: getIcon(0),title: getTabTitle(0)),
          new BottomNavigationBarItem(icon: getIcon(1),title: getTabTitle(1)),
          new BottomNavigationBarItem(icon: getIcon(2),title: getTabTitle(2)),
          new BottomNavigationBarItem(icon: getIcon(3),title: getTabTitle(3)),
          new BottomNavigationBarItem(icon: getIcon(4),title: getTabTitle(4))
        ],
        // 默认选中
        currentIndex: _currentIndex,
        //点击事件
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        // 底部导航栏展示方式,shifting选中文字显示,fixed选中文字略微变大
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}

